********************************************************************************
**  TITLE:      il2021_ines_contact_networks                                  **  
**  AUTHOR:	    Philippe Mongrain                                             **
**  DATA:       March_2020_data		                                          **
**  DATE:	    October 2022 					                              **	
**  VERSION:    Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "il2021_ines_contact_networks", replace

* Open the dataset

use "March_2021_data_website_STATA.dta", clear 


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen surveydate=date(date, "DMY")

format %tdMon_DD,_CCYY surveydate

gen edate = 20210323

gen electiondate=date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = (electiondate - surveydate)

* Gender

gen male = gender

recode male (2=0)

* Age

replace age = . if age < 17

* Education

gen education = educ

recode education 99=.

* Coalition preference

gen coalpref = .

replace coalpref = 9999 if v107 == .
replace coalpref = 9999 if v107 == 98 | v107 == 99

replace coalpref = 1 if v107 == 4 & coalpref!=9999

replace coalpref = 0 if v107!=4 & coalpref!=1 & coalpref!=9999

replace coalpref = . if coalpref == 9999

label define coalpref 0 "Losing preference" 1 "Winning preference"
label values coalpref coalpref

* News attentiveness

gen news = v611

recode news 98=.

* Minimum threshold for representation in elections to the Knesset - Correct answers (3.25%; close answers also considered as correct) = 1, Incorrect answer = 0

gen threshold = v73

recode threshold (99=.)

replace threshold = 0 if threshold!=1 & threshold!=. // Incorrect answer
replace threshold = 1 if threshold == 1 // Correct answer

* President of the Supreme Court - Correct answer (Esther Hayut) = 1, Incorrect answer = 0

gen supreme = v510

recode supreme (99=.)

replace supreme = 0 if supreme!=1 & supreme!=. // Incorrect answer
replace supreme = 1 if supreme == 1 // Correct answer

* Ministry with largest budget (other than Defense) - Correct answer (Education) = 1, Incorrect answer = 0

gen budget = v511

recode budget (99=.)

replace budget = 0 if budget!=4 & budget!=. // Incorrect answer
replace budget = 1 if budget == 4 // Correct answer

* Political knowledge index

gen knowledge = threshold + supreme + budget

* Political discussion

gen discussion = v45

recode discussion 98=.

replace discussion = 4 - discussion

gen discussion_3pts = discussion
replace discussion_3pts = 0 if discussion == 1
replace discussion_3pts = 1 if discussion == 2
replace discussion_3pts = 2 if discussion == 3


*********************************
** NATIONAL-LEVEL EXPECTATIONS **
*********************************

* Forecasts

gen forecast_whole = v106

recode forecast_whole 98=. 99=.

* Identify correct forecasts

gen correct_whole_d = 0 if forecast_whole!=4 & forecast_whole!=.
replace correct_whole_d = 1 if forecast_whole == 4 & forecast_whole!=.


**********
** SAVE **
**********

save "il2021_ines.dta", replace


*******************
** MAIN ANALYSES **
*******************

* Regression analysis and percentage of correct and incorrect forecasts

logistic correct_whole_d discussion i.coalpref news knowledge age i.male education time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_whole_d "Coalition formed (DV)"
label variable discussion "Discussion"
label variable coalpref "Coalition preference"
label variable news "News attentiveness"
label variable knowledge "Political knowledge"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"

estpost tabstat correct_whole_d discussion coalpref news knowledge age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "il2021_ines_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2021 Israeli legislative election (INES), national level") replace

eststo clear

log close